package com.rede.didiok.admin.restapi.admin;


import java.util.List;

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.admin.annotion.AuthorityVerify.AuthorityVerify;
import com.rede.didiok.admin.annotion.OperationLogger.OperationLogger;
import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.community.UserMomentDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.feign.CommunityFeignClient;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;

/**
 * 用户动态表 RestApi
 *
 * @author Rede
 * @date 2023年10月26日08:25:36
 */
@Api(value = "用户动态相关接口", tags = {"用户动态相关接口"})
@RestController
@RequestMapping("/admin/userMoment")
@Slf4j
public class UserMomentRestApi {

    @Resource
    private CommunityFeignClient communityFeignClient;

    @AuthorityVerify
    @ApiOperation(value = "获取用户动态列表", notes = "获取用户动态列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody UserMomentDto userMomentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取用户动态列表");
        return communityFeignClient.getUserMomentPageList(userMomentDto);
    }

    @AvoidRepeatableCommit
    @AuthorityVerify
    @OperationLogger(value = "增加用户动态")
    @ApiOperation(value = "增加用户动态", notes = "增加用户动态", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody UserMomentDto userMomentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("增加用户动态");
        return communityFeignClient.addUserMoment(userMomentDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "编辑用户动态")
    @ApiOperation(value = "编辑用户动态", notes = "编辑用户动态", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody UserMomentDto userMomentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑用户动态");
        return communityFeignClient.editUserMoment(userMomentDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "批量删除用户动态")
    @ApiOperation(value = "批量删除用户动态", notes = "批量删除用户动态", response = String.class)
    @PostMapping("/deleteBatch")
    public String delete(@Validated({Delete.class}) @RequestBody List<UserMomentDto> userMomentDtoList, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("批量删除用户动态");
        return communityFeignClient.deleteBatchUserMoment(userMomentDtoList);
    }

    @AuthorityVerify
    @OperationLogger(value = "审核用户动态")
    @ApiOperation(value = "审核用户动态", notes = "审核用户动态", response = String.class)
    @PostMapping("/audit")
    public String audit(@RequestBody UserMomentDto userMomentDto) {
        return communityFeignClient.auditMoment(userMomentDto);
    }

}

